﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using G.Navigate;
using G.Reader.Data;
using System.Text;

namespace G.Reader.View
{
    public partial class RSSDetailPage : GBasePage
    {
        public RSSDetailPage()
        {
            InitializeComponent();
        }
        FeedItem feedItem;
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (feedItem == null)
            {
                feedItem = this.NavigationContext.Param as FeedItem;
                this.PageTitle.Text = feedItem.Title;
                this.webBrowser.NavigateToString(ConvertExtendedASCII(feedItem.Content));
                G.Animation.ItemFlyInAndOutAnimations.TitleFlyIn(this.PageTitle);
            }
        }

        private string ConvertExtendedASCII(string HTML)
        {
            StringBuilder str = new StringBuilder();
            char c;
            for (int i = 0; i < HTML.Length; i++)
            {
                c = HTML[i];
                if (Convert.ToInt32(c) > 127)
                {
                    str.Append("&#" + Convert.ToInt32(c) + ";");
                }
                else
                {
                    str.Append(c);
                }
            }
            return str.ToString();
        }

        private void btnDetail_Click(object sender, EventArgs e)
        {
            this.NavigationService.Navigate("/View/WebBrowserPage.xaml?url=" + feedItem.Link.AbsoluteUri);
        }
    }
}